sclp_early.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * SCLP early driver
  3. *
  4. * Copyright IBM Corp. 2013
  5. */
  6. #define KMSG_COMPONENT "sclp_early"
  7. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  8. #include <asm/ctl_reg.h>
  9. #include <asm/sclp.h>
  10. #include <asm/ipl.h>
  11. #include "sclp_sdias.h"
  12. #include "sclp.h"
  13. #define SCLP_CMDW_READ_SCP_INFO 0x00020001
  14. #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
  15. struct read_info_sccb {
  16. struct sccb_header header; /* 0-7 */
  17. u16 rnmax; /* 8-9 */
  18. u8 rnsize; /* 10 */
  19. u8 _reserved0[24 - 11]; /* 11-15 */
  20. u8 loadparm[8]; /* 24-31 */
  21. u8 _reserved1[48 - 32]; /* 32-47 */
  22. u64 facilities; /* 48-55 */
  23. u8 _reserved2[84 - 56]; /* 56-83 */
  24. u8 fac84; /* 84 */
  25. u8 fac85; /* 85 */
  26. u8 _reserved3[91 - 86]; /* 86-90 */
  27. u8 flags; /* 91 */
  28. u8 _reserved4[100 - 92]; /* 92-99 */
  29. u32 rnsize2; /* 100-103 */
  30. u64 rnmax2; /* 104-111 */
  31. u8 _reserved5[4096 - 112]; /* 112-4095 */
  32. } __packed __aligned(PAGE_SIZE);
  33. static char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE) __initdata;
  34. static unsigned int sclp_con_has_vt220 __initdata;
  35. static unsigned int sclp_con_has_linemode __initdata;
  36. static unsigned long sclp_hsa_size;
  37. static struct sclp_ipl_info sclp_ipl_info;
  38. u64 sclp_facilities;
  39. u8 sclp_fac84;
  40. unsigned long long sclp_rzm;
  41. unsigned long long sclp_rnmax;
  42. static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
  43. {
  44. int rc;
  45. __ctl_set_bit(0, 9);
  46. rc = sclp_service_call(cmd, sccb);
  47. if (rc)
  48. goto out;
  49. __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
  50. PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
  51. local_irq_disable();
  52. out:
  53. /* Contents of the sccb might have changed. */
  54. barrier();
  55. __ctl_clear_bit(0, 9);
  56. return rc;
  57. }
  58. static int __init sclp_read_info_early(struct read_info_sccb *sccb)
  59. {
  60. int rc, i;
  61. sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
  62. SCLP_CMDW_READ_SCP_INFO};
  63. for (i = 0; i < ARRAY_SIZE(commands); i++) {
  64. do {
  65. memset(sccb, 0, sizeof(*sccb));
  66. sccb->header.length = sizeof(*sccb);
  67. sccb->header.function_code = 0x80;
  68. sccb->header.control_mask[2] = 0x80;
  69. rc = sclp_cmd_sync_early(commands[i], sccb);
  70. } while (rc == -EBUSY);
  71. if (rc)
  72. break;
  73. if (sccb->header.response_code == 0x10)
  74. return 0;
  75. if (sccb->header.response_code != 0x1f0)
  76. break;
  77. }
  78. return -EIO;
  79. }
  80. static void __init sclp_facilities_detect(struct read_info_sccb *sccb)
  81. {
  82. if (sclp_read_info_early(sccb))
  83. return;
  84. sclp_facilities = sccb->facilities;
  85. sclp_fac84 = sccb->fac84;
  86. if (sccb->fac85 & 0x02)
  87. S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
  88. sclp_rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
  89. sclp_rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
  90. sclp_rzm <<= 20;
  91. /* Save IPL information */
  92. sclp_ipl_info.is_valid = 1;
  93. if (sccb->flags & 0x2)
  94. sclp_ipl_info.has_dump = 1;
  95. memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
  96. }
  97. bool __init sclp_has_linemode(void)
  98. {
  99. return !!sclp_con_has_linemode;
  100. }
  101. bool __init sclp_has_vt220(void)
  102. {
  103. return !!sclp_con_has_vt220;
  104. }
  105. unsigned long long sclp_get_rnmax(void)
  106. {
  107. return sclp_rnmax;
  108. }
  109. unsigned long long sclp_get_rzm(void)
  110. {
  111. return sclp_rzm;
  112. }
  113. /*
  114. * This function will be called after sclp_facilities_detect(), which gets
  115. * called from early.c code. The sclp_facilities_detect() function retrieves
  116. * and saves the IPL information.
  117. */
  118. void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
  119. {
  120. *info = sclp_ipl_info;
  121. }
  122. static int __init sclp_cmd_early(sclp_cmdw_t cmd, void *sccb)
  123. {
  124. int rc;
  125. do {
  126. rc = sclp_cmd_sync_early(cmd, sccb);
  127. } while (rc == -EBUSY);
  128. if (rc)
  129. return -EIO;
  130. if (((struct sccb_header *) sccb)->response_code != 0x0020)
  131. return -EIO;
  132. return 0;
  133. }
  134. static void __init sccb_init_eq_size(struct sdias_sccb *sccb)
  135. {
  136. memset(sccb, 0, sizeof(*sccb));
  137. sccb->hdr.length = sizeof(*sccb);
  138. sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
  139. sccb->evbuf.hdr.type = EVTYP_SDIAS;
  140. sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
  141. sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
  142. sccb->evbuf.event_id = 4712;
  143. sccb->evbuf.dbs = 1;
  144. }
  145. static int __init sclp_set_event_mask(struct init_sccb *sccb,
  146. unsigned long receive_mask,
  147. unsigned long send_mask)
  148. {
  149. memset(sccb, 0, sizeof(*sccb));
  150. sccb->header.length = sizeof(*sccb);
  151. sccb->mask_length = sizeof(sccb_mask_t);
  152. sccb->receive_mask = receive_mask;
  153. sccb->send_mask = send_mask;
  154. return sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
  155. }
  156. static long __init sclp_hsa_size_init(struct sdias_sccb *sccb)
  157. {
  158. sccb_init_eq_size(sccb);
  159. if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
  160. return -EIO;
  161. if (sccb->evbuf.blk_cnt != 0)
  162. return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
  163. return 0;
  164. }
  165. static long __init sclp_hsa_copy_wait(struct sccb_header *sccb)
  166. {
  167. memset(sccb, 0, PAGE_SIZE);
  168. sccb->length = PAGE_SIZE;
  169. if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
  170. return -EIO;
  171. return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
  172. }
  173. unsigned long sclp_get_hsa_size(void)
  174. {
  175. return sclp_hsa_size;
  176. }
  177. static void __init sclp_hsa_size_detect(void *sccb)
  178. {
  179. long size;
  180. /* First try synchronous interface (LPAR) */
  181. if (sclp_set_event_mask(sccb, 0, 0x40000010))
  182. return;
  183. size = sclp_hsa_size_init(sccb);
  184. if (size < 0)
  185. return;
  186. if (size != 0)
  187. goto out;
  188. /* Then try asynchronous interface (z/VM) */
  189. if (sclp_set_event_mask(sccb, 0x00000010, 0x40000010))
  190. return;
  191. size = sclp_hsa_size_init(sccb);
  192. if (size < 0)
  193. return;
  194. size = sclp_hsa_copy_wait(sccb);
  195. if (size < 0)
  196. return;
  197. out:
  198. sclp_hsa_size = size;
  199. }
  200. static unsigned int __init sclp_con_check_linemode(struct init_sccb *sccb)
  201. {
  202. if (!(sccb->sclp_send_mask & (EVTYP_OPCMD_MASK | EVTYP_PMSGCMD_MASK)))
  203. return 0;
  204. if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
  205. return 0;
  206. return 1;
  207. }
  208. static void __init sclp_console_detect(struct init_sccb *sccb)
  209. {
  210. if (sccb->header.response_code != 0x20)
  211. return;
  212. if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
  213. sclp_con_has_vt220 = 1;
  214. if (sclp_con_check_linemode(sccb))
  215. sclp_con_has_linemode = 1;
  216. }
  217. void __init sclp_early_detect(void)
  218. {
  219. void *sccb = &sccb_early;
  220. sclp_facilities_detect(sccb);
  221. sclp_hsa_size_detect(sccb);
  222. /* Turn off SCLP event notifications. Also save remote masks in the
  223. * sccb. These are sufficient to detect sclp console capabilities.
  224. */
  225. sclp_set_event_mask(sccb, 0, 0);
  226. sclp_console_detect(sccb);
  227. }