sclp_early.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 <linux/errno.h>
  9. #include <asm/ctl_reg.h>
  10. #include <asm/sclp.h>
  11. #include <asm/ipl.h>
  12. #include "sclp_sdias.h"
  13. #include "sclp.h"
  14. #define SCLP_CMDW_READ_SCP_INFO 0x00020001
  15. #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001
  16. struct read_info_sccb {
  17. struct sccb_header header; /* 0-7 */
  18. u16 rnmax; /* 8-9 */
  19. u8 rnsize; /* 10 */
  20. u8 _pad_11[16 - 11]; /* 11-15 */
  21. u16 ncpurl; /* 16-17 */
  22. u16 cpuoff; /* 18-19 */
  23. u8 _pad_20[24 - 20]; /* 20-23 */
  24. u8 loadparm[8]; /* 24-31 */
  25. u8 _pad_32[42 - 32]; /* 32-41 */
  26. u8 fac42; /* 42 */
  27. u8 fac43; /* 43 */
  28. u8 _pad_44[48 - 44]; /* 44-47 */
  29. u64 facilities; /* 48-55 */
  30. u8 _pad_56[66 - 56]; /* 56-65 */
  31. u8 fac66; /* 66 */
  32. u8 _pad_67[76 - 67]; /* 67-83 */
  33. u32 ibc; /* 76-79 */
  34. u8 _pad80[84 - 80]; /* 80-83 */
  35. u8 fac84; /* 84 */
  36. u8 fac85; /* 85 */
  37. u8 _pad_86[91 - 86]; /* 86-90 */
  38. u8 flags; /* 91 */
  39. u8 _pad_92[99 - 92]; /* 92-98 */
  40. u8 hamaxpow; /* 99 */
  41. u32 rnsize2; /* 100-103 */
  42. u64 rnmax2; /* 104-111 */
  43. u8 _pad_112[116 - 112]; /* 112-115 */
  44. u8 fac116; /* 116 */
  45. u8 fac117; /* 117 */
  46. u8 _pad_118; /* 118 */
  47. u8 fac119; /* 119 */
  48. u16 hcpua; /* 120-121 */
  49. u8 _pad_122[124 - 122]; /* 122-123 */
  50. u32 hmfai; /* 124-127 */
  51. u8 _pad_128[4096 - 128]; /* 128-4095 */
  52. } __packed __aligned(PAGE_SIZE);
  53. static char sccb_early[PAGE_SIZE] __aligned(PAGE_SIZE) __initdata;
  54. static struct sclp_ipl_info sclp_ipl_info;
  55. struct sclp_info sclp;
  56. EXPORT_SYMBOL(sclp);
  57. static int __init sclp_cmd_sync_early(sclp_cmdw_t cmd, void *sccb)
  58. {
  59. int rc;
  60. __ctl_set_bit(0, 9);
  61. rc = sclp_service_call(cmd, sccb);
  62. if (rc)
  63. goto out;
  64. __load_psw_mask(PSW_DEFAULT_KEY | PSW_MASK_BASE | PSW_MASK_EA |
  65. PSW_MASK_BA | PSW_MASK_EXT | PSW_MASK_WAIT);
  66. local_irq_disable();
  67. out:
  68. /* Contents of the sccb might have changed. */
  69. barrier();
  70. __ctl_clear_bit(0, 9);
  71. return rc;
  72. }
  73. static int __init sclp_read_info_early(struct read_info_sccb *sccb)
  74. {
  75. int rc, i;
  76. sclp_cmdw_t commands[] = {SCLP_CMDW_READ_SCP_INFO_FORCED,
  77. SCLP_CMDW_READ_SCP_INFO};
  78. for (i = 0; i < ARRAY_SIZE(commands); i++) {
  79. do {
  80. memset(sccb, 0, sizeof(*sccb));
  81. sccb->header.length = sizeof(*sccb);
  82. sccb->header.function_code = 0x80;
  83. sccb->header.control_mask[2] = 0x80;
  84. rc = sclp_cmd_sync_early(commands[i], sccb);
  85. } while (rc == -EBUSY);
  86. if (rc)
  87. break;
  88. if (sccb->header.response_code == 0x10)
  89. return 0;
  90. if (sccb->header.response_code != 0x1f0)
  91. break;
  92. }
  93. return -EIO;
  94. }
  95. static void __init sclp_facilities_detect(struct read_info_sccb *sccb)
  96. {
  97. struct sclp_core_entry *cpue;
  98. u16 boot_cpu_address, cpu;
  99. if (sclp_read_info_early(sccb))
  100. return;
  101. sclp.facilities = sccb->facilities;
  102. sclp.has_sprp = !!(sccb->fac84 & 0x02);
  103. sclp.has_core_type = !!(sccb->fac84 & 0x01);
  104. sclp.has_gsls = !!(sccb->fac85 & 0x80);
  105. sclp.has_64bscao = !!(sccb->fac116 & 0x80);
  106. sclp.has_cmma = !!(sccb->fac116 & 0x40);
  107. sclp.has_esca = !!(sccb->fac116 & 0x08);
  108. sclp.has_pfmfi = !!(sccb->fac117 & 0x40);
  109. sclp.has_ibs = !!(sccb->fac117 & 0x20);
  110. sclp.has_hvs = !!(sccb->fac119 & 0x80);
  111. if (sccb->fac85 & 0x02)
  112. S390_lowcore.machine_flags |= MACHINE_FLAG_ESOP;
  113. sclp.rnmax = sccb->rnmax ? sccb->rnmax : sccb->rnmax2;
  114. sclp.rzm = sccb->rnsize ? sccb->rnsize : sccb->rnsize2;
  115. sclp.rzm <<= 20;
  116. sclp.ibc = sccb->ibc;
  117. if (sccb->hamaxpow && sccb->hamaxpow < 64)
  118. sclp.hamax = (1UL << sccb->hamaxpow) - 1;
  119. else
  120. sclp.hamax = U64_MAX;
  121. if (!sccb->hcpua) {
  122. if (MACHINE_IS_VM)
  123. sclp.max_cores = 64;
  124. else
  125. sclp.max_cores = sccb->ncpurl;
  126. } else {
  127. sclp.max_cores = sccb->hcpua + 1;
  128. }
  129. boot_cpu_address = stap();
  130. cpue = (void *)sccb + sccb->cpuoff;
  131. for (cpu = 0; cpu < sccb->ncpurl; cpue++, cpu++) {
  132. if (boot_cpu_address != cpue->core_id)
  133. continue;
  134. sclp.has_siif = cpue->siif;
  135. sclp.has_sigpif = cpue->sigpif;
  136. sclp.has_sief2 = cpue->sief2;
  137. sclp.has_gpere = cpue->gpere;
  138. sclp.has_ib = cpue->ib;
  139. sclp.has_cei = cpue->cei;
  140. sclp.has_skey = cpue->skey;
  141. break;
  142. }
  143. /* Save IPL information */
  144. sclp_ipl_info.is_valid = 1;
  145. if (sccb->flags & 0x2)
  146. sclp_ipl_info.has_dump = 1;
  147. memcpy(&sclp_ipl_info.loadparm, &sccb->loadparm, LOADPARM_LEN);
  148. sclp.mtid = (sccb->fac42 & 0x80) ? (sccb->fac42 & 31) : 0;
  149. sclp.mtid_cp = (sccb->fac42 & 0x80) ? (sccb->fac43 & 31) : 0;
  150. sclp.mtid_prev = (sccb->fac42 & 0x80) ? (sccb->fac66 & 31) : 0;
  151. sclp.hmfai = sccb->hmfai;
  152. }
  153. /*
  154. * This function will be called after sclp_facilities_detect(), which gets
  155. * called from early.c code. The sclp_facilities_detect() function retrieves
  156. * and saves the IPL information.
  157. */
  158. void __init sclp_get_ipl_info(struct sclp_ipl_info *info)
  159. {
  160. *info = sclp_ipl_info;
  161. }
  162. static int __init sclp_cmd_early(sclp_cmdw_t cmd, void *sccb)
  163. {
  164. int rc;
  165. do {
  166. rc = sclp_cmd_sync_early(cmd, sccb);
  167. } while (rc == -EBUSY);
  168. if (rc)
  169. return -EIO;
  170. if (((struct sccb_header *) sccb)->response_code != 0x0020)
  171. return -EIO;
  172. return 0;
  173. }
  174. static void __init sccb_init_eq_size(struct sdias_sccb *sccb)
  175. {
  176. memset(sccb, 0, sizeof(*sccb));
  177. sccb->hdr.length = sizeof(*sccb);
  178. sccb->evbuf.hdr.length = sizeof(struct sdias_evbuf);
  179. sccb->evbuf.hdr.type = EVTYP_SDIAS;
  180. sccb->evbuf.event_qual = SDIAS_EQ_SIZE;
  181. sccb->evbuf.data_id = SDIAS_DI_FCP_DUMP;
  182. sccb->evbuf.event_id = 4712;
  183. sccb->evbuf.dbs = 1;
  184. }
  185. static int __init sclp_set_event_mask(struct init_sccb *sccb,
  186. unsigned long receive_mask,
  187. unsigned long send_mask)
  188. {
  189. memset(sccb, 0, sizeof(*sccb));
  190. sccb->header.length = sizeof(*sccb);
  191. sccb->mask_length = sizeof(sccb_mask_t);
  192. sccb->receive_mask = receive_mask;
  193. sccb->send_mask = send_mask;
  194. return sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_MASK, sccb);
  195. }
  196. static long __init sclp_hsa_size_init(struct sdias_sccb *sccb)
  197. {
  198. sccb_init_eq_size(sccb);
  199. if (sclp_cmd_early(SCLP_CMDW_WRITE_EVENT_DATA, sccb))
  200. return -EIO;
  201. if (sccb->evbuf.blk_cnt == 0)
  202. return 0;
  203. return (sccb->evbuf.blk_cnt - 1) * PAGE_SIZE;
  204. }
  205. static long __init sclp_hsa_copy_wait(struct sccb_header *sccb)
  206. {
  207. memset(sccb, 0, PAGE_SIZE);
  208. sccb->length = PAGE_SIZE;
  209. if (sclp_cmd_early(SCLP_CMDW_READ_EVENT_DATA, sccb))
  210. return -EIO;
  211. if (((struct sdias_sccb *) sccb)->evbuf.blk_cnt == 0)
  212. return 0;
  213. return (((struct sdias_sccb *) sccb)->evbuf.blk_cnt - 1) * PAGE_SIZE;
  214. }
  215. static void __init sclp_hsa_size_detect(void *sccb)
  216. {
  217. long size;
  218. /* First try synchronous interface (LPAR) */
  219. if (sclp_set_event_mask(sccb, 0, 0x40000010))
  220. return;
  221. size = sclp_hsa_size_init(sccb);
  222. if (size < 0)
  223. return;
  224. if (size != 0)
  225. goto out;
  226. /* Then try asynchronous interface (z/VM) */
  227. if (sclp_set_event_mask(sccb, 0x00000010, 0x40000010))
  228. return;
  229. size = sclp_hsa_size_init(sccb);
  230. if (size < 0)
  231. return;
  232. size = sclp_hsa_copy_wait(sccb);
  233. if (size < 0)
  234. return;
  235. out:
  236. sclp.hsa_size = size;
  237. }
  238. static unsigned int __init sclp_con_check_linemode(struct init_sccb *sccb)
  239. {
  240. if (!(sccb->sclp_send_mask & EVTYP_OPCMD_MASK))
  241. return 0;
  242. if (!(sccb->sclp_receive_mask & (EVTYP_MSG_MASK | EVTYP_PMSGCMD_MASK)))
  243. return 0;
  244. return 1;
  245. }
  246. static void __init sclp_console_detect(struct init_sccb *sccb)
  247. {
  248. if (sccb->header.response_code != 0x20)
  249. return;
  250. if (sccb->sclp_send_mask & EVTYP_VT220MSG_MASK)
  251. sclp.has_vt220 = 1;
  252. if (sclp_con_check_linemode(sccb))
  253. sclp.has_linemode = 1;
  254. }
  255. void __init sclp_early_detect(void)
  256. {
  257. void *sccb = &sccb_early;
  258. sclp_facilities_detect(sccb);
  259. sclp_hsa_size_detect(sccb);
  260. /* Turn off SCLP event notifications. Also save remote masks in the
  261. * sccb. These are sufficient to detect sclp console capabilities.
  262. */
  263. sclp_set_event_mask(sccb, 0, 0);
  264. sclp_console_detect(sccb);
  265. }