sclp_early.c 6.8 KB

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